module libeventd.rpc.Intelnal;

import
	libeventd.Types;

extern(C):


struct evrpc_hook {
	TAILQ_ENTRY!(evrpc_hook) next;
	ev_int function(void*, evhttp_request*,evbuffer*,void*)	process;
	void*	process_arg;
}

struct evrpc_hook_list{
	mixin	TAILQ_HEAD!(evrpc_hook);
}

struct evrpc_hook_ctx {
	TAILQ_ENTRY!(evrpc_hook_ctx)			next;
	void*							ctx;
	void function(void *, EVRPC_HOOK_RESULT)	cb;
}

struct evrpc_pause_list{
	mixin	TAILQ_HEAD!(evrpc_hook_ctx);
}

struct _evrpc_hooks {
	evrpc_hook_list		in_hooks;
	evrpc_hook_list		out_hooks;
	evrpc_pause_list		pause_requests;
}

struct evrpc_list{
	mixin TAILQ_HEAD!(evrpc) ;
}

struct evrpc_base {
	_evrpc_hooks	common;
	evhttp*		http_server;
	evrpc_list		registered_rpcs;
}

void evrpc_reqstate_free(evrpc_req_generic*);

struct evrpc_requestq{
	mixin TAILQ_HEAD!(evrpc_request_wrapper);
}

struct evrpc_pool {
	_evrpc_hooks	common;
	event_base*	base;
	evconq		connections;
	ev_int 		timeout;
	evrpc_requestq	equests;
}



struct evrpc_meta {
	TAILQ_ENTRY!(evrpc_meta)	next;
	char*		key;
	void*		data;
	size_t 		data_size;
}

struct evrpc_meta_list{
	mixin TAILQ_HEAD!(evrpc_meta);
}

struct evrpc_hook_meta {
	evrpc_meta_list		meta_data;
	evhttp_connection*	evcon;
}


struct evrpc_req_generic {
	evrpc_hook_meta*	hook_meta;
	void*			request;
	void*			reply;
	evrpc*			rpc;
	evhttp_request*		http_req;
	evbuffer*			rpc_data;
}

struct evrpc_request_wrapper {
	evrpc_hook_meta*				hook_meta;
	TAILQ_ENTRY!(evrpc_request_wrapper)	next;
	evrpc_pool*					pool;
	evhttp_connection*				evcon;
	evhttp_request*					req;
	event						ev_timeout;
	char*	name;
	void function(evrpc_status*, void*, void*, void*) cb;
	void*						cb_arg;
	void*						request;
	void*						reply;
	void function(evbuffer*, void*)		request_marshal;
	void function(void*)				reply_clear;
	ev_int function(void*, evbuffer*)		reply_unmarshal;
}
